
import {
  ElMessage
} from 'element-plus'
import i18n from '@/lang'
let messageInstance = null

const resetMessage = (options) => {
  if (messageInstance) {
    messageInstance.close()
  }
  messageInstance = ElMessage(options)
}
['error', 'success', 'info', 'warning'].forEach(type => {
  resetMessage[type] = options => {
    if (typeof options === 'string') {
      options = {
        message: i18n.global.t(options),
        type: type,
        showClose: true
      }
    }
    return resetMessage(options)
  }
})
resetMessage.close = () => {
  if (messageInstance) {
    messageInstance.close()
  }
}
export const message = resetMessage
